//
//  AlterPswViewController.m
//  HomeDelivery
//
//  Created by apple on 16/7/25.
//  Copyright © 2016年 apple. All rights reserved.
//

#import "AlterPswViewController.h"

@interface AlterPswViewController ()


@end

@implementation AlterPswViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor=LIGHTGRAY;
    self.title=@"修改密码";
    self.sureAlterBtn.layer.cornerRadius=5;
    self.sureAlterBtn.clipsToBounds=YES;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
   
}

- (IBAction)sureAlterPsw:(id)sender
{
    if (self.pswTx.text.length==0) {
        [MBProgressHUD showError:@"请输入密码"];
    }else if (self.pswAgainTx.text.length==0)
    {
        [MBProgressHUD showError:@"请输入确认密码"];
    }else if (self.pswTx.text.length<6)
    {
        [MBProgressHUD showError:@"密码过于简单"];
    }else if (self.pswTx.text.length>20)
    {
        [MBProgressHUD showError:@"密码不要太长哦~"];
    }else if ([GeneralTool isPureNumandCharacters:self.pswTx.text])
    {
        [MBProgressHUD showError:@"密码不要纯数字哦~"];
    }else if (![self.pswAgainTx.text isEqualToString:self.pswTx.text])
    {
        [MBProgressHUD showError:@"两次密码不一致"];
    }
    else
    {
       // http://192.168.1.107:35568/User/ModPwd
       //m_ModPwdPara(AdminAccount,Mobile,Code,NewPwd,Timestamp,Sign)
        NSString *timeStamp=[GeneralTool gettimestamp];
        NSString *AdminAccount=nil;
        NSDictionary *dic=nil;
        if(ADMINACCOUNT)
        {
            AdminAccount=ADMINACCOUNT;
            dic=@{@"AdminAccount":AdminAccount,
                  @"Mobile":_mobile,
                  @"Code":_verifyCode,
                  @"NewPwd":[_pswAgainTx.text MD5],
                  @"Timestamp":timeStamp};
        }else
        {
            AdminAccount=@"";
            dic=@{
                  @"Mobile":_mobile,
                  @"Code":_verifyCode,
                  @"NewPwd":[_pswAgainTx.text MD5],
                  @"Timestamp":timeStamp};
        }
        NSString *sign=[GeneralTool GetSin:dic];
        NSDictionary *dataDic=@{@"AdminAccount":AdminAccount,
                                @"Mobile":_mobile,
                                @"Code":_verifyCode,
                                @"NewPwd":[_pswAgainTx.text MD5],
                                @"Timestamp":timeStamp,
                                @"Sign":sign};
        NSDictionary *requestDic=@{@"m_ModPwdPara":dataDic};
        [RequestTool requestDataWithType:@"post" andUrlString:@"User/ModPwd" andParameters:requestDic andFinishedWith:^(id response, NSError *error)
        {
            if (error) {
                [MBProgressHUD showError:@"修改失败"];
            }else
            {
                if ([response[@"IsSuccess"]integerValue]==1)
                {
                    [MBProgressHUD showSuccess:response[@"ReturnString"]];
                    [self.navigationController popToRootViewControllerAnimated:YES];
                    
                }else
                {
                    [MBProgressHUD showError:response[@"ReturnString"]];
                }
            }
            
        }];

        
        
    }
}

@end
